package day18.zhiyou100;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

// 测试类
class Test3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建FutureTask类对象/Thread类对象/MyCallable实现类对象
        MyCallable myCallable = new MyCallable();
        MyCallable myCallable1 = new MyCallable();
        FutureTask task1 = new FutureTask<Integer>(myCallable);
        Thread t1 = new Thread(task1);
        // 调用start()方法
        t1.start();

        // 获取任务执行的结果方法get()
        Integer obj = (Integer) task1.get();
        System.out.println("分线程执行的结果为：" + obj);

        for (int i = 0; i < 50; i++) {
            System.out.println(Thread.currentThread().getName() + "---" + i);
        }

    }

}


public class MyCallable implements Callable {

    //计算两个数的和
    @Override
    public Integer call() throws Exception {
        int a = 100;
        int b = 200;
        return a + b;//a + b ---->int--->Integer--->Object(多态)
    }

}
